package beans;

import beansInterfaces.ConstraintsMgr;

import javax.ejb.Stateless;

import dto.PackageDTO;

/**
 * Session Bean implementation class ConstraintsMgrBean
 */
@Stateless

public class ConstraintsMgrBean implements ConstraintsMgr {

    public ConstraintsMgrBean() {
    }
    
    @Override
	public float autoSetPrice(PackageDTO p)
	{
		float x,y,z,w;
		if(p.getResidence()!= null && p.getResidence().getPrice()!=null)
			x = p.getResidence().getPrice();
		else
			x=0;
		
		if(p.getExcursion()!= null && p.getExcursion().getPrice()!=null)
			y = p.getExcursion().getPrice();
		else
			y=0;
		
		if(p.getDepartureTransport()!= null && p.getDepartureTransport().getPrice()!= null)
			z = p.getDepartureTransport().getPrice();
		else
			z=0;
		
		if(p.getReturnTransport()!= null && p.getReturnTransport().getPrice()!= null)
			w = p.getReturnTransport().getPrice();
		else
			w=0;
		
		float packagePrize;
		if (p.getDiscount()!=null)
		{
			packagePrize = (x+y+z+w) - (x+y+z+w)*(p.getDiscount()/100);
		}
		else
			packagePrize =0;
		
		
		return packagePrize;
		
	}
	
	@Override
	public boolean isComplete(PackageDTO p)
	{
		if(p==null || 
				p.getExcursion()==null || 
				p.getDepartureTransport()==null ||
				p.getReturnTransport()==null||
				p.getResidence()==null)
		{
			return false;
		}
		return true;
	}
	
	@Override
	public boolean existsOneNotDisponible(PackageDTO p)
	{
		if( p.getResidence().getDisponibility() == 0 || 
			p.getExcursion().getDisponibility() == 0 ||
			p.getDepartureTransport().getDisponibility() == 0||
			p.getReturnTransport().getDisponibility()==0 ||
			p.getResidence().isAvailable() == false || 
			p.getExcursion().isAvailable() == false ||
			p.getDepartureTransport().isAvailable() == false ||
			p.getReturnTransport().isAvailable() == false )
				return true;
		return false;
	}
    
    

}
